<?php
if(empty($buid))
msg($config['weburl']."/login.php");
else
{
    $param = $_POST;
    if(empty($param['item'])){
        echo "<script>alert('请选择票价');window.history.back();</script>";
        return false;
    }

    $m_sql = "select * from ".SPOTMODEL." where spot_id = '{$param['spot']}' ";
    $db->query($m_sql);
    $seat_model = $db->getRows();

    foreach($seat_model as $key => $val){

        $s_sql = "select * from ".SPOTSEAT." where spot_id = '{$param['spot']}' and model_id = '{$val['id']}'  ";
        $db->query($s_sql);
        $seats = $db->getRows();
        foreach($seats as $k => $v){
            $seat_model[$key]['row'][$k] = $v['row'];
            $seat_model[$key]['seat'][$k] = explode(',',$v['seat']);
        }
    }

    $tpl->assign('seat',$seat_model);
    $tpl->assign('seat_other',$seat_model);
    //票品信息
    foreach($param['item'] as $key => $val){
        $explode = explode(',',$val);
        $p_sql = "select * from ".SETMEAL." where pid= '{$param['pid']}'  and performance_start_time = '{$explode[0]}' and price = '{$explode[1]}'  ";
        $db->query($p_sql);
        $p_info = $db->fetchRow();
        $product_list[$key] = $p_info;
        $price_list[$key] = $p_info['price'];
    }

    //已勾选的座位
    $pro_sql = "select * from ".ORPRO." where pid= '{$product_list[0]['pid']}' and spot_id = '{$param['spot']}' and spot_model_id !='' ";
    $db->query($pro_sql);
    $select_seat = $db->getRows();
    $buy_seat = []; //已买过的座位
    $ch_buy_seat = [];
    if(!empty($select_seat)) {
        foreach($select_seat as $key=>$val){
            $spot_model[$key] = unserialize($val['spot_model_id']);
            $spot_model_row[$key] = unserialize($val['seat_seat_row']);
            $spot_model_cols[$key] = unserialize($val['seat_seat_cols']);

        }

        foreach($spot_model as $key  => $val){
            foreach($val as $k=> $v){
                $buy_seat[$key][$k] = $v.','.$spot_model_row[$key][$k].','.$spot_model_cols[$key][$k];
            }
        }
        if(!empty($buy_seat)){
            foreach($buy_seat as $key => $val){
                foreach($val as $k=> $v) {
                    $ch_buy_seat[] = $v;
                }
            }
        }

    }

    $tpl->assign('product_list',$product_list);
    $tpl->assign('price_list',$price_list);
    $tpl->assign('param',$param);
    $tpl->assign('buy_seat',$buy_seat);
    $tpl->assign('ch_buy_seat',$ch_buy_seat);

}


//=================================================
$tpl->assign("config",$config);
$tpl->assign("current","product");
include_once("footer.php");

$out=tplfetch("shop_product_select.htm",$flag,true);

?>